import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: () => import('@/views/layout/index.vue'),
      children: [
        // 首页
        {
          path: '',
          name: 'home',
          component: () => import('@/views/Home/index.vue'),
        },
        // 二级商品 面包屑
        {
          path: '/category/:id',
          name: 'Category',
          component: () => import('@/views/Category/index.vue'),
        },
        // 三级商品 面包屑
        {
          path: '/category/sub/:id',
          name: 'SubCategory',
          component: () => import('@/views/SubCategory/index.vue'),
        },
        // 详情
        {
          path: '/detail/:id',
          name: 'detail',
          component: () => import('@/views/Detail/index.vue'),
        },
        // 购物车
        {
          path: '/cartList',
          name: 'cartList',
          component: () => import('@/views/CartList/index.vue'),
        },
        // 订单页
        {
          path: '/checkout',
          name: 'checkout',
          component: () => import('@/views/Checkout/index.vue'),
        },
        // 结算页
        {
          path: '/pay',
          name: 'pay',
          component: () => import('@/views/Pay/index.vue'),
        },
        // 结算完成页
        {
          path: '/paycallback',
          name: 'paycallback',
          component: () => import('@/views/Pay/PayBack.vue'),
        },
        // 个人中心页
        {
          path: '/member',
          name: 'member',
          component: () => import('@/views/Member/index.vue'),
          children: [
            // 个人信息组件页
            {
              path: '',
              name: 'user',
              component: () => import('@/views/Member/UserInfo.vue'),
            },
            // 我的订单组件
            {
              path: 'order',
              name: 'order',
              component: () => import('@/views/Member/UserOrder.vue'),
            },
          ]
        },
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login/index.vue')
    },
    {
      path: '/loginPlumb',
      name: 'loginPlumb',
      component: () => import('@/views/Plumb/index.vue')
    }
  ],
  scrollBehavior() {
    return { top: 0 }
  }
})

export default router
